﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _meetSanta : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSubmit.Click +=new ImageClickEventHandler(btnSubmit_Click);
        
    }

    void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
     
        if (IsValid)
        {
            Chimes.DataContext context = new Chimes.DataContext();
            Chimes.Santa santa = new Chimes.Santa();

            santa.Name = txtName.Text;
            santa.ParentName = txtParentName.Text;
            santa.Email = txtEmail.Text;
            santa.Telephone = txtTelephone.Text;
            santa.Presents = txtPresents.Text;
            santa.Optout = chkOptout.Checked;
            
            context.Santas.InsertOnSubmit(santa);
            context.SubmitChanges();

            string emailPath = "~/email/santa.xml";
            Email santaEmail = new Email(santa.Email, Server.MapPath(emailPath));
            santaEmail.Format("Name", santa.Name);
            santaEmail.Format("Email", santa.Email);
            santaEmail.Send();

            pnlEntry.Visible = false;
            pnlThankyou.Visible = true;
        }
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = chkTC.Checked; 
    }
}
